package net.googlecode.exigenlab.task5;

import net.googlecode.exigenlab.task5.calculator.Calculator;
import net.googlecode.exigenlab.task5.calculator.SalaryCalculatorFactory;
import net.googlecode.exigenlab.task5.model.Boss;
import net.googlecode.exigenlab.task5.model.Employee;
import net.googlecode.exigenlab.task5.model.Manager;
import net.googlecode.exigenlab.task5.model.Person;
import net.googlecode.exigenlab.task5.sort.Sorter;

import java.math.BigDecimal;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

/**
 * Main application for calculating salary for person
 */
public class SalaryApp {
    private static final BigDecimal BOSS_TAX = new BigDecimal(500);
    private static final BigDecimal MANAGER_TAX = new BigDecimal(250);
    private static final BigDecimal EMPLOYEE_TAX = new BigDecimal(125);

    public static void main(String[] args) {
        Manager boss = createBoss();
        Manager manager1 = createManager1();
        Manager manager2 = createManager2();
        Manager manager3 = createManager3();
        Manager employee1 = createEmployee1();
        Manager employee2 = createEmployee2();
        Manager employee3 = createEmployee3();
        Manager employee4 = createEmployee4();
        Manager employee5 = createEmployee5();
        Manager employee6 = createEmployee6();
        Collection<Manager> workers = new ArrayList<Manager>();
        workers.add(boss);
        workers.add(manager1);
        workers.add(manager2);
        workers.add(manager3);
        workers.add(employee1);
        workers.add(employee2);
        workers.add(employee3);
        workers.add(employee4);
        workers.add(employee5);
        workers.add(employee6);
        Sorter sort = new Sorter();
        if (args.length > 0) {
            if (args[0].equals("code")) {
                Collection<Manager> testCollection = sort.sortById(workers);
                System.out.println(testCollection);
            } else if (args[0].equals("lastname")) {
                Collection<Manager> testCollection = sort.sortByName(workers);
                System.out.println(testCollection);
            } else if (args[0].equals("salary")) {
                Collection<Manager> testCollection = sort.sortBySalary(workers);
                System.out.println(testCollection);
            } else {
                System.out.println("error option");
            }
        } else {
            System.out.println("enter option");
        }
    }


    private static BigDecimal calculateSalary(Manager person, BigDecimal tax) {
        Calculator salaryCalculator = SalaryCalculatorFactory.getCalculator(person);
        salaryCalculator.setTax(tax);
        return salaryCalculator.calculateSalary(person);
    }

    public static Boss createBoss() {
        Boss boss = new Boss();
        boss.setFirstName("Sasha");
        boss.setLastName("Petrov");
        boss.setAge(35);
        boss.setBonusAmount(new BigDecimal(1000));
        boss.setRate(new BigDecimal(50));
        boss.setKey("000");
        boss.setSalary(calculateSalary(boss,BOSS_TAX));

        return boss;
    }

    public static Manager createManager1() {
        Manager manager = new Manager();
        manager.setFirstName("Ivan");
        manager.setLastName("Ivanov");
        manager.setAge(30);
        manager.setPerHour(true);
        manager.setBonus(false);
        manager.setRate(new BigDecimal(25));
        manager.setKey("111");
        manager.setSalary(calculateSalary(manager,MANAGER_TAX));

        return manager;
    }

    public static Manager createManager2() {
        Manager manager = new Manager();
        manager.setFirstName("Roma");
        manager.setLastName("Morechkov");
        manager.setAge(27);
        manager.setPerHour(true);
        manager.setBonus(false);
        manager.setRate(new BigDecimal(25));
        manager.setKey("233");
        manager.setSalary(calculateSalary(manager,MANAGER_TAX));

        return manager;
    }

    public static Manager createManager3() {
        Manager manager = new Manager();
        manager.setFirstName("Satasia");
        manager.setLastName("Basilis");
        manager.setAge(60);
        manager.setPerHour(true);
        manager.setBonus(false);
        manager.setRate(new BigDecimal(25));
        manager.setKey("654");
        manager.setSalary(calculateSalary(manager,MANAGER_TAX));

        return manager;
    }

    public static Employee createEmployee1() {
        Employee employee = new Employee();
        employee.setFirstName("Semen");
        employee.setLastName("Semenov");
        employee.setAge(18);
        employee.setBonus(true);
        employee.setBonusAmount(new BigDecimal(1500));
        employee.setPerHour(true);
        employee.setRate(new BigDecimal(8));
        employee.setKey("772");
        employee.setSalary(calculateSalary(employee,EMPLOYEE_TAX));

        return employee;
    }
    public static Employee createEmployee2() {
        Employee employee = new Employee();
        employee.setFirstName("Petr");
        employee.setLastName("Semechkov");
        employee.setAge(33);
        employee.setBonus(true);
        employee.setBonusAmount(new BigDecimal(1500));
        employee.setPerHour(true);
        employee.setRate(new BigDecimal(8));
        employee.setKey("236");
        employee.setSalary(calculateSalary(employee,EMPLOYEE_TAX));

        return employee;
    }
    public static Employee createEmployee3() {
        Employee employee = new Employee();
        employee.setFirstName("Jenia");
        employee.setLastName("Udochkin");
        employee.setAge(25);
        employee.setBonus(true);
        employee.setBonusAmount(new BigDecimal(1500));
        employee.setPerHour(true);
        employee.setRate(new BigDecimal(8));
        employee.setKey("333");
        employee.setSalary(calculateSalary(employee,EMPLOYEE_TAX));

        return employee;
    }
    public static Employee createEmployee4() {
        Employee employee = new Employee();
        employee.setFirstName("Misha");
        employee.setLastName("Tolmachev");
        employee.setAge(40);
        employee.setBonus(true);
        employee.setBonusAmount(new BigDecimal(1500));
        employee.setPerHour(true);
        employee.setRate(new BigDecimal(8));
        employee.setKey("754");
        employee.setSalary(calculateSalary(employee,EMPLOYEE_TAX));

        return employee;
    }
    public static Employee createEmployee5() {
        Employee employee = new Employee();
        employee.setFirstName("Urij");
        employee.setLastName("Gorlov");
        employee.setAge(43);
        employee.setBonus(true);
        employee.setBonusAmount(new BigDecimal(1500));
        employee.setPerHour(true);
        employee.setRate(new BigDecimal(8));
        employee.setKey("125");
        employee.setSalary(calculateSalary(employee,EMPLOYEE_TAX));

        return employee;
    }
    public static Employee createEmployee6() {
        Employee employee = new Employee();
        employee.setFirstName("Andrej");
        employee.setLastName("Palkov");
        employee.setAge(19);
        employee.setBonus(true);
        employee.setBonusAmount(new BigDecimal(1500));
        employee.setPerHour(true);
        employee.setRate(new BigDecimal(8));
        employee.setKey("123");
        employee.setSalary(calculateSalary(employee,EMPLOYEE_TAX));

        return employee;
    }

}
